/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wf.ui;

import bc.dsl.PageDSL;
import bc.dsl.SwingDSL;
import bc.swing.pfrm.Model;
import bc.swing.pfrm.ano.Action;
import bc.swing.pfrm.ano.PageDef;
import bc.swing.pfrm.ano.Param;
import bc.swing.pfrm.viewtypes.ParamType;
import java.util.LinkedList;
import java.util.List;
import wf.ui.layouts.MainLayout;
import wf.units.ApplicationUnit;

/**
 *
 * @author bennyl
 */
@PageDef(name = "Watering System Managment", icon = "logo128", layout = MainLayout.class)
public class WFUserInterface extends Model {

    List<Model> views;

    @Param(name = "Active User Name", type = ParamType.LABEL, role = MainLayout.USER_NAME_ROLE)
    public String getActiveUserName() {
        return ApplicationUnit.UNIT.getRegisteredUser().getName();
    }

    @Param(name = "Views", type = ParamType.TABS, role = MainLayout.VIEWS_ROLE)
    public List<Model> getViews() {
        return views;
    }

    @Action(name = "Switch To Administrator Console", icon = "admin-console22")
    public void handleUserSwitch() {
        if (ApplicationUnit.UNIT.getRegisteredUser().isAdmin()) {
            PageDSL.showInNonClosingFrame(new AdminConsole());
        }else {
            SwingDSL.errbox("Unauthorized access", "you must be admin to access this screen.");
        }
    }

    @Action(name = "Logout", icon = "close16")
    public void handleDisconnect() {
        getPage().disposeView();
        ApplicationUnit.UNIT.restartUI();
    }

    public void startUI() {
        SwingDSL.configureUI();

        ApplicationUnit.UNIT.invokeUserRegistration();

        views = new LinkedList<Model>();
        views.add(new SchedueManager());
        views.add(new StatisticsManager());


        PageDSL.showInFrame(this);
    }
}
